package com.nxy.test.socket;

import java.io.*;
import java.net.Socket;

/**
 * Created by snailnan on 2017/2/20.
 */
public class ServerThread implements Runnable{
    private Socket client ;
    public ServerThread(Socket s){
        this.client = s;
    }
    public void run() {
        try {
            InputStream i = client.getInputStream();
            OutputStream o = client.getOutputStream();
            BufferedReader reader =  new BufferedReader(new InputStreamReader(i));
            PrintStream ps = new PrintStream(o);
            boolean flag = true;
            while (flag){
                String str = reader.readLine();
                if (str != null && !"".equals(str)){
                    System.out.println(str);
//                    ps.println("hello "+ str);
                }else{
                    flag = false;
                }
            }
            i.close();
            o.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
